import {
  roleSave, getUserList
} from "@/api/auth";
import { remoteMethod } from "@/utils/form";
export default {
  data() {
    return {
      editForm: {
        visible: false,
        // 子组件的初始化的内容
        form: null,
        formAttrs: {
          "label-width": "80px"
        },
        title: ["编辑角色", "新增角色"],
        formType: "add",
        options: [
          {
            type: "select",
            value: "",
            hide: false,
            prop: "userIds",
            label: "角色人员",
            attrs: {
              placeholder: "请选择角色人员",
              style: {
                width: "200px"
              },
              loading: false,
              clearable: true,
              multiple: true,
              filterable: true,
              remote: true,
              reserveKeyword: true,
              remoteMethod: (query) => remoteMethod("editForm", "userIds", this, getUserList, query, ["name", "id"], "key")
            },
            rules: [
              {
                required: true,
                message: "角色人员不能为空",
                trigger: "blur"
              }
            ],
            childern: []
          },
          {
            type: "input",
            value: "",
            label: "角色名称",
            prop: "name",
            hide: false,
            rules: [
              {
                required: true,
                message: "角色名称不能为空",
                trigger: "blur"
              }
            ],
            attrs: {
              placeholder: "请输入角色名称",
              style: {
                width: "200px"
              }
            }
          },
          {
            type: "input",
            value: "",
            hide: false,
            prop: "remark",
            label: "角色备注",
            attrs: {
              placeholder: "请输入角色备注",
              type: "textarea",
              style: {
                width: "200px"
              }
            }
          },
          {
            type: "input",
            value: "",
            prop: "id",
            label: "iD",
            hide: true
          },
          {
            type: "input",
            value: "QM",
            prop: "sysName",
            label: "",
            hide: true
          }
        ]
      }
    };
  },
  methods: {

    async save(formData) {
      const data = JSON.parse(JSON.stringify(formData));
      data.userIds = data.userIds.join(",");
      await roleSave(data);
      this.$message.success("操作成功");
      await this.search();
      this.editForm.visible = false;
    }

  }
};
